﻿// ***********************************************************************
// Assembly         : LYB.NET.Infrastructure
// Author           : 李玉宝
// Created          : 12-07-2013
//
// Last Modified By : 李玉宝
// Last Modified On : 12-07-2013
// ***********************************************************************
// <copyright file="Log4NetAdapter.cs">
//     Copyright (c) 李玉宝 All rights reserved.
// </copyright>
// <summary>采用log4net记录日志</summary>
// add configuration of app.config:
//<configuration>
//  <appSettings>
//    <add key="log4net.Config" value="log4net.config"/>
//  </appSettings>
//</configuration>
// ***********************************************************************

using System;
using log4net;
using log4net.Config;

namespace DataMonitor.Logging
{
    public class Log4NetAdapter : ILogger
    {
        private readonly ILog _log;

        private static readonly ILogger _instance = new Log4NetAdapter();
        public static ILogger Instance { get { return _instance; } }

        private Log4NetAdapter()
        {
            XmlConfigurator.Configure();
            _log = LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
        }
        public void Write(string message)
        {
            _log.Info(message);
        }

        public void Write(Exception exception)
        {
            _log.Error(exception.Message, exception);

        }
    }
}

